package com.service.impl;

import com.bean.BookLike;
import com.mapper.BookLikeMapper;
import com.service.BookLikeService;
import com.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookLikeServiceImpl implements BookLikeService {
    @Autowired
    private BookLikeMapper bookLikeMapper;

    @Override
    public BookLike getBookLikeById(Integer likeId) {
        return bookLikeMapper.getBookLikeById(likeId);
    }

    @Override
    public PageInfo<BookLike> getBookLikesWithKeyword(String keyword, int pageNum, int pageSize) {
        int offset = (pageNum - 1) * pageSize;
        List<BookLike> bookLikes = bookLikeMapper.getBookLikesWithKeyword(keyword, offset, pageSize);
        int total = bookLikeMapper.countBookLikesWithKeyword(keyword);
        return new PageInfo<>(pageNum, pageSize, total, bookLikes);
    }

    @Override
    public boolean insertBookLike(BookLike bookLike) {
        int result = bookLikeMapper.insertBookLike(bookLike);
        return result > 0;
    }

    @Override
    public boolean deleteBookLikeById(Integer likeId) {
        int result = bookLikeMapper.deleteBookLikeById(likeId);
        return result > 0;
    }
}